﻿using System;
using System.Windows.Forms;

using FileSynchronizer.DataAccess;

namespace FileSynchronizer
{
    public partial class Form_ShowLog : Form
    {
        #region Private variables
        //---------------------------------------------------------------------------------------------------------------------------------------
        private FolderPair myFolderPair;
        private SyncDatabaseHelper mySyncDatabaseHelper;
        //---------------------------------------------------------------------------------------------------------------------------------------
        #endregion

        #region Public variables and properties
        //---------------------------------------------------------------------------------------------------------------------------------------
        public FolderPair FolderPair
        {
            get
            {
                return myFolderPair;
            }
            set
            {
                myFolderPair = value;
            }
        }
        //---------------------------------------------------------------------------------------------------------------------------------------
        #endregion
        
        
        #region Constructors
        //---------------------------------------------------------------------------------------------------------------------------------------
        public Form_ShowLog()
        {
            InitializeComponent();

            if (myFolderPair != null)
            {
                mySyncDatabaseHelper = new SyncDatabaseHelper(); ;

                folderPairLogBindingSource.DataSource = mySyncDatabaseHelper.AllFolderPairLogs(myFolderPair);
            }
        }

        public Form_ShowLog(FolderPair TheFolderPair)
        {
            InitializeComponent();
            
            myFolderPair = TheFolderPair;
            if (myFolderPair != null)
            {
                mySyncDatabaseHelper = new SyncDatabaseHelper(); ;

                folderPairLogBindingSource.DataSource = mySyncDatabaseHelper.AllFolderPairLogs(myFolderPair);
            }
        }

        //---------------------------------------------------------------------------------------------------------------------------------------
        #endregion

        #region Event Handlers
        //---------------------------------------------------------------------------------------------------------------------------------------
        // Called when the User clicks the "Clear Logs" Button
        //---------------------------------------------------------------------------------------------------------------------------------------
        private void OnClearLog_Click(object sender, EventArgs e)
        {
            if (myFolderPair != null)
            {
                if (MessageBox.Show("Are you sure you want to remove the logs?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    if (mySyncDatabaseHelper.DeleteFolderPairLogs(myFolderPair))
                    {
                        MessageBox.Show("Logs were removed");
                        DialogResult = DialogResult.OK;
                    }
                }
            }
        }
        //---------------------------------------------------------------------------------------------------------------------------------------
        #endregion
    }
}
